home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: Storing C Functions In An Array?
- Date: 28 Mar 1996 18:55:12 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4jenag$394@sparcserver.lrz-muenchen.de>
- References: <4jc1u7$5e9@infa.central.susx.ac.uk>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- tepd6@central.susx.ac.uk (George Rattray) writes:
-
- >Can someone help me, I'm trying to store functions in an array at
- >compile time. The following functions are defined as
-
- > struct complex func(struct complex, CHNL);
-
- >I want to store them in an array ch[N];
-
- >Therefor using the function with an index as
-
- > ret = ch[0](x,chnl);
-
- >Any help will be most appreciated, Thanks
-
- This can be done using function pointers. Since a function "name"
- mentioned in an expression decays to a pointer to that function,
- and since you can easily call a function through a pointer, there
- is no need to declare an "array of functions".
-
- typedef struct compley (* func)(struct compley, CHNL);
-
- func ch[N];
-
- ret = ch[0](x, chnl);
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-
-